<template>
  <div class="apply-result">
    <template v-if="status === 1">
      <img class="result-img" v-if="fileSpace" :src="fileSpace + '/images/store-apply-pass.png'" alt="">
      <div class="tip-text">开通成功！获得{{ storeApply ? '门店' : '团长' }}功能权限</div>
      <div class="home-btn" @click="goHome">进入首页</div>
    </template>
    <template v-else-if="status === 0">
      <img class="result-img" v-if="fileSpace" :src="fileSpace + '/images/store-apply-padding.png'" alt="">
      <div class="panding">
        <div>请耐心等待</div>
        <div>审核通过后获得{{ storeApply ? '门店' : '团长' }}功能权限</div>
      </div>
    </template>
    <template v-else-if="status === 2">
      <div class="tip-text">开通失败！请重新申请</div>
    </template>
    <template v-else-if="status === 3">
      <div class="tip-text">{{ msg }}</div>
    </template>
  </div>
</template>
<script>
import { getCommanderApply } from '@/api/home'
export default {
  data() {
    return {
      status: '',
      memberId: '',
      phone: '',
      bindStatus: '',
      msg: '',
      applyName: '',
      storeApply: false
    }
  },
  onShow() {
    this.storeApply = this.$pt.getStorageSync('store-applied') // 获取门店申请缓存，判断是申请门店还是申请团长
    this.bindStatus = this.getCurrentPage().query.bindStatus
    this.msg = this.getCurrentPage().query.msg
    if (this.bindStatus === '1') {
      this.$pt.removeStorageSync('bindCommander')
      this.$pt.removeStorageSync('scanCode')
      this.$pt.removeStorageSync('store-applied')
      this.status = 1
      this.$pt.setNavigationBarTitle({
        title: '开通成功'
      })
      this.$pt.removeStorageSync('leader-applied')
    } else {
      this.$pt.removeStorageSync('bindCommander')
      this.$pt.removeStorageSync('scanCode')
      this.$pt.removeStorageSync('store-applied')
      this.status = 3
    }
  },
  mounted() {
    if (!this.bindStatus) {
      this.memberId = this.getCurrentPage().query.memberId
      this.phone = this.getCurrentPage().query.phone
      let storeApplied = this.$pt.getStorageSync('store-applied')
      if (storeApplied) {
        // 已提交申请门店，会自动审核通过
        this.status = 1
        this.$pt.setNavigationBarTitle({
          title: '开通成功'
        })
        this.$pt.removeStorageSync('store-applied')
      } else {
        // 申请团长过来的，要检查团长申请结果
        this.getCommanderApply()
      }
      console.log('result 555')
    }
  },
  methods: {
    getCommanderApply() {
      // 查询申请团长结果
      getCommanderApply({
        memberId: this.memberId
      }).then(response => {
        if (response.isError) return
        console.log(111111111)
        this.status = response.data.status
        if (this.status === 1) {
          this.$pt.setNavigationBarTitle({
            title: '开通成功'
          })
          this.$pt.removeStorageSync('leader-applied')
        } else if (this.status === 2) {
          this.$pt.setNavigationBarTitle({
            title: '开通失败'
          })
        } else if (this.status === 0) {
          this.$pt.setNavigationBarTitle({
            title: '开通审核中'
          })
        }
      }).catch(() => {
      })
    },
    goHome() {
      console.log('result 333')
      this.$pt.switchTab({ url: '/pages/home/main' })
    }
  }
}
</script>
<style lang="less" scoped>
.apply-result{
  padding-top: 34px;
  min-height: 100vh;
  box-sizing: border-box;
  background-color: #fff;
  .result-img{
    width: 150px;
    height: 150px;
    margin: 0 auto;
    background-color: #eee;
    border-radius: 50%;
  }
  .tip-text{
    margin-top: 17px;
    text-align: center;
    font-size: 20px;
    font-weight: bold;
  }
  .home-btn{
    width: 180px;
    height: 45px;
    line-height: 45px;
    text-align: center;
    border-radius: 22px;
    background-color: #FF1717;
    color: #FFF;
    margin: 0 auto;
    font-size: 16px;
    margin-top: 75px;
    font-weight: bold;
  }
  .panding{
    margin-top: 22px;
    font-size: 16px;
    color: #999999;
    text-align: center;
    line-height: 24px;
  }
}
</style>
